{extend name="/base"}

{block name="header"}
    <h2>添加权限</h2>
{/block}

{block name="body"}
    <form class="layui-form">
        {include file="permission/_form" /}
    </form>
{/block}

{block name="js"}

<script>
    layui.use(['jquery','table','element','form','layer'],function () {
        var table=layui.table;
        var $=layui.jquery;
        var element=layui.element;
        var form=layui.form;
        var layer=layui.layer;

        //选择图标
        window.chioceIcon = function (obj) {
            var icon = $(obj).data('class');
            $("input[name='icon']").val(icon);
            $("#icon_box").html('<i class="layui-icon '+$(obj).data('class')+'"></i> '+$(obj).data('name'));
            layer.closeAll();
        }

        //弹出图标
        window.showIconsBox = function () {
            var index = layer.load();
            $.get("__STATIC__/icons.json",function (res) {
                layer.close(index);
                var html = '<ul class="site-doc-icon">';
                $.each(res,function (index,item) {
                    html += '<li onclick="chioceIcon(this)" data-class="'+item.class+'" data-name="'+item.name+'" >';
                    html += '   <i class="layui-icon '+item.class+'"></i>';
                    html += '   <div class="doc-icon-name">'+item.name+'</div>';
                    html += '   <div class="doc-icon-code"><xmp>'+item.unicode+'</xmp></div>';
                    html += '   <div class="doc-icon-fontclass">'+item.class+'</div>';
                    html += '</li>'
                });
                html += '</ul>';
                layer.open({
                    type:1,
                    title:'选择图标',
                    area : ['1080px','600px'],
                    content:html
                })
            },'json')
        }

        form.on('submit(formDemo)',function (data) {
            var load = layer.load();
            $.post("{:url()}",data.field,function (res) {
                layer.close(load);
                if (res.code==1){
                    layer.msg(res.msg,{icon:1,time:1500},function () {
                        if (res.url) location.href = res.url;
                    })
                } else {
                    layer.msg(res.msg,{icon:2,time:1500})
                }
            });
            return false
        })

    })
</script>
{/block}